package com.ruoyi.bus.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.bus.service.NoGenerateServlce;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bus.domain.CustBase;
import com.ruoyi.bus.service.ICustBaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户基础信息Controller
 *
 * @author ruoyi
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/bus/custBase")
public class CustBaseController extends BaseController {
    private String prefix = "bus/custBase";

    @Autowired
    private ICustBaseService custBaseService;

    @Autowired
    private NoGenerateServlce noGenerateServlce;

    @RequiresPermissions("bus:custBase:view")
    @GetMapping()
    public String custBase() {
        return prefix + "/custBase";
    }

            /**
         * 查询客户基础信息列表
         */
        @RequiresPermissions("bus:custBase:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(CustBase custBase) {
            startPage();
            return getDataTable(custBaseService.list(new QueryWrapper<>(custBase)));
        }
    
    /**
     * 导出客户基础信息列表
     */
    @RequiresPermissions("bus:custBase:export")
    @Log(title = "客户基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CustBase custBase) {
        List<CustBase> list = custBaseService.list(new QueryWrapper<>(custBase));
        ExcelUtil<CustBase> util = new ExcelUtil<>(CustBase.class);
        return util.exportExcel(list, "custBase");
    }

            /**
         * 新增客户基础信息
         */
        @GetMapping("/add")
        public String add(ModelMap mmap) {
            CustBase custBase = new CustBase();
            custBase.setCustomerId(noGenerateServlce.getSeqNo("CU",6));
            mmap.put("custBase", custBase);
            return prefix + "/edit";
        }
    
    /**
     * 新增保存客户基础信息
     */
    @RequiresPermissions("bus:custBase:add")
    @Log(title = "客户基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CustBase custBase) {
        return toAjax(custBaseService.save(custBase));
    }

    /**
     * 修改客户基础信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        CustBase custBase = custBaseService.getById(id);
        mmap.put("custBase", custBase);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户基础信息
     */
    @RequiresPermissions("bus:custBase:edit")
    @Log(title = "客户基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CustBase custBase) {
        return toAjax(custBaseService.updateById(custBase));
    }

            /**
         * 删除客户基础信息
         */
        @RequiresPermissions("bus:custBase:remove")
        @Log(title = "客户基础信息", businessType = BusinessType.DELETE)
        @PostMapping( "/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(custBaseService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
        }
        }
